package huoye.shops.huoye.mine.activity;

import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.codeideology.android.utils.StringUtils;

import java.math.BigDecimal;

import butterknife.BindView;
import butterknife.OnClick;
import huoye.shops.R;
import huoye.shops.base.BaseActivity;
import huoye.shops.base.UserManager;
import huoye.shops.huoye.mine.model.WithdrawHome;
import huoye.shops.huoye.mine.presenter.WithdrawPresenter;
import huoye.shops.huoye.mine.view.IWithdrawView;
import huoye.shops.utils.StockUtils;

public class WithdrawActivity extends BaseActivity implements IWithdrawView {

    @BindView(R.id.withdraw_tv_money)
    TextView tvMoney;

    @BindView(R.id.withdraw_tv_withdraw_money)
    TextView tvWithdrawMoney;
    @BindView(R.id.withdraw_tv_sell_money)
    TextView tvSellMoney;
    @BindView(R.id.withdraw_tv_push_money)
    TextView tvPushMoney;

    @BindView(R.id.withdraw_et_withdraw_money)
    EditText etMoney;
    @BindView(R.id.withdraw_et_withdraw_account)
    EditText etAccount;
    private WithdrawPresenter mWithdrawPresenter;

    @OnClick(R.id.withdraw_btn_pay_record)
    void onRecordClick() {
        startActivity(RecordPayActivity.class);
    }

    @OnClick(R.id.withdraw_btn_submit_put)
    void onSubmitClick() {
        String mAccount = etAccount.getText().toString();
        String mMoney = etMoney.getText().toString();
        UserManager.getInstance().saveWithdrawAccount(mAccount);

        mWithdrawPresenter.Withdraw(mMoney, mAccount);

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_withdraw;
    }

    @Override
    protected void initView(@Nullable Bundle bundle) {
        setTitle("提现");
        String withdrawAccount = UserManager.getInstance().getWithdrawAccount();
        if (StringUtils.isNotEmpty(withdrawAccount)) {
            etAccount.setText(withdrawAccount);
        }

        mWithdrawPresenter = new WithdrawPresenter();
        mWithdrawPresenter.addTaskListener(this);
        mWithdrawPresenter.onStart();
        mWithdrawPresenter.getDepositIndex();
    }

    @Override
    public void setWithdrawData(WithdrawHome withdrawHome) {
        BigDecimal moeny= StockUtils.moenyStyle(withdrawHome.getBalance());
        tvMoney.setText(moeny+"");

        BigDecimal withdrawMoney= StockUtils.moenyStyle(withdrawHome.getDepositAmount());
        tvWithdrawMoney.setText(withdrawMoney+"");

        if(withdrawHome.getOrderAmount() == null){
            withdrawHome.setOrderAmount("0");
         }
         BigDecimal sellMoney= StockUtils.moenyStyle(withdrawHome.getOrderAmount());
        tvSellMoney.setText(sellMoney+"");
        BigDecimal pushMoney= StockUtils.moenyStyle(withdrawHome.getBlockAmount());
        tvPushMoney.setText(pushMoney+"");
    }
}
